/*
 * Part of knowledge engineering (ke) course work, 2010/11
 */
package se.bth.ke.firstfriend.util;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;

/**
 * Provides a number of useful utility methods
 * @author nico.rehwaldt
 */
public class Util {

    public static final String TODO_DEADLINE_FORMAT_STRING = "yyyy/MM/dd";
    public static final DateFormat TODO_DEADLINE_FORMAT =
                new SimpleDateFormat(TODO_DEADLINE_FORMAT_STRING);

    public static final String PRODUCES_HTML =
        "text/html;qs=4, application/xhtml+xml;qs=3, application/json;qs=2, application/xml;qs=1";
    
    public static boolean isAjax(HttpServletRequest request) {
        return "XMLHttpRequest".equals(request.getHeader("X-Requested-With"));
    }

    public static Date parseDate(String s) throws ParseException {
        if (s == null || s.isEmpty()) {
            return null;
        } else {
            return TODO_DEADLINE_FORMAT.parse(s);
        }
    }

    public static final Map<Integer, String> TODO_PRIORITY_MAP = new HashMap() {{
        put(0, "quite unimportant");
        put(1, "at least a bit important");
        put(2, "very important");
    }};
}
